package main

import (
	"fmt"
	"strconv"
	"unsafe"
)

func main() {
	var num1 int8 = 23
	var num2 int8 = -10
	fmt.Println("有符号整数类型 int8,int32,int64")
	fmt.Println("定义一个整数类型：int8 -127~128 var num1 int8 = 23 值 ", num1, num2)
	fmt.Println("无符号整数类型 uint >0")

	var num3 = 28
	fmt.Println("Pringf函数作用是格式化数据类型 ")
	fmt.Printf("num3的类型是：%T", num3)
	fmt.Println()
	fmt.Println("num3数据字节数：", unsafe.Sizeof(num3))
	var age uint8 = 254
	fmt.Println("uint8：", age)
	fmt.Println("-------------")
	fmt.Println("浮点类型")
	var num4 float32 = 3.14
	fmt.Print("var num4 float32 = 3.14 => ", num4)
	fmt.Println("------------")
	fmt.Println("字符类型，本质是一个ASCII整数，可以直接参与运算")
	var c1 byte = 'a'
	fmt.Println("var c1 byte = 'a' => ", c1)
	fmt.Println("golang的字符对应使用的utf-8编码,中对应码值20013，byte类型溢出，所以用int接收")
	var c2 int = '中'
	fmt.Println("var c2 int = '中' => ", c2)
	var c3 byte = 'A'
	fmt.Printf("var c3 byte = 'A' 格式化对应的字符是：%c", c3)
	fmt.Println("-------转义字符---------")
	//换行\n 退格\b 光标回本行开头后续输出替换原有字符\r  制表符8个一组 \t
	fmt.Println("aaaaa\nbbbbb")
	fmt.Println("aaaa\bbbbbb")
	fmt.Println("aaaaa\rbbbbb")
	fmt.Println("aaaaa\tbbbbb")
	fmt.Println("输出带引号的字符串 \"Golang\"")
	fmt.Println("------布尔值-------")

	var flag1 bool = true
	fmt.Println("var flag1 bool = true => ", flag1)
	var flag2 bool = false
	fmt.Println("var flag2 bool = false => ", flag2)
	var flag3 bool = 5 < 9
	fmt.Println("var flag3 bool = 5 < 9 => ", flag3)
	fmt.Println("------字符串-------")
	var s1 string = "学习golang"
	fmt.Println(s1)
	var s2 string = `
	fmt.Println("var flag3 bool = 5 < 9 => ", flag3)
	fmt.Println("------字符串-------")
	var s1 string = "学习golang"
	fmt.Println(s1)`
	fmt.Println("反引号输出代码字符串 ", s2)
	fmt.Println("------数据类型默认值-------")
	var a int
	var b float32
	var c float64
	var d bool
	var e string
	fmt.Println(a, b, c, d, e)
	fmt.Println("数据类型转换：")
	var z1 = 100
	var z2 float32 = float32(z1)
	fmt.Println("显示转换 var z2 float32 = float32(z1) => ", z1, z2)
	fmt.Println("------数据类型转字符串-------")
	var z3 int = 19
	var z4 float64 = 4.78
	//var z5 bool = true
	var zz1 string = fmt.Sprintf("%d", z3)
	fmt.Printf("数据类型转字符串：fmt.Sprintf => %T %v", zz1, zz1)
	fmt.Println()
	var zz2 string = strconv.FormatFloat(z4, 'f', 9, 64)
	fmt.Println("9 表示保留9位小数，63代表float64格式")
	fmt.Printf("zz2对应类型：%T, zz2 = %v", zz2, zz2)
	fmt.Println("字符串转基本类型")
	var g1 string = "true"
	var g2 bool
	g2, _ = strconv.ParseBool(g1)
	fmt.Printf("g2对应类型：%T, zz2 = %v", g2, g2)
	fmt.Println("连接成功！")
}
